/**
 *
 * @author DorcasBless
 * you can find the Synaxarium at http://code.google.com/p/synaxarium/
 * April, 2009
 * Version 1.0.0
 *
 */

package com.christian;

import java.util.Calendar;
import java.util.Date;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;

public class DateSearchForm extends Form implements CommandListener{

    private SynMIDlet synMIDlet;
    private DateField dateField = new DateField ("\u0627\u0628\u062D\u062B \u0628\u0627\u0644\u062A\u0627\u0631\u064A\u062E",DateField.DATE);
    private Command backCommand = new Command("\u0631\u062C\u0648\u0639", Command.BACK, 0);
    private Command searchCommand = new Command("\u0628\u062D\u062B", Command.OK, 0);

    public DateSearchForm (SynMIDlet synMIDlet)
    {
        super("\u0628\u062D\u062B \u0628\u0627\u0644\u062A\u0627\u0631\u064A\u062E");
        this.synMIDlet = synMIDlet;
        dateField.setDate(new Date());
        append(dateField);
        addCommand(backCommand);
        addCommand(searchCommand);
        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) {
        if (c==backCommand)
        {
            //synMIDlet.showMainScreen();
            //synMIDlet.getCanvas().update();
            synMIDlet.showSameMainScreen();
        }
        else if (c==searchCommand)
        {
            SynMIDlet.calendar.setTime(dateField.getDate());
            if (synMIDlet.getCanvas().init(SynMIDlet.getCorrectDate(SynMIDlet.calendar.get(Calendar.YEAR), SynMIDlet.calendar.get(Calendar.MONTH)+1, SynMIDlet.calendar.get(Calendar.DAY_OF_MONTH))))
            {
                synMIDlet.showNewMainScreen();
            }
            
        }
    }

}
